﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Auth.Application.IServices.System;
using Auth.Dtos.System;
using Auth.Models;
using Auth.Models.System;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace Auth.Web.Api.Apis.System
{
    /// <summary>
    /// 数据字典接口
    /// </summary>
    public class SettingController : ApiController
    {
        /// <summary>
        /// 服务接口
        /// </summary>
        private readonly ISettingService _service;

        /// <summary>
        /// Constructor
        /// </summary>
        public SettingController(ISettingService service)
        {
            _service = service;
        }

        /// <summary>
        /// 查询单条记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<SettingDto> GetAsync(Guid id)
        {
            return await _service.GetAsync(id);
        }

        /// <summary>
        /// 新增数据字典
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Guid?> InsertAsync(SettingDto dto)
        {
            return await _service.InsertAsync(dto);
        }

        /// <summary>
        /// 更新数据字典
        /// </summary>
        /// <param name="settingDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<bool> UpdateAsync(SettingDto dto)
        {
            return await _service.UpdateAsync(dto);
        }

        /// <summary>
        /// 删除数据字典
        /// </summary>
        /// <param name="settingDto"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<bool> DeleteAsync(SettingDto dto)
        {
            return await _service.DeleteAsync(dto);
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="settingDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagedList<SettingDto>> GetPagedListAsync(SettingModel model)
        {
            return await _service.GetPagedListAsync(model);
        }

        /// <summary>
        /// 根据key查询结果
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet("{key}")]
        public async Task<List<SettingDto>> GetListAsync(string key)
        {
            return await _service.GetListAsync(key);
        }
    }
}
